<template>
	<view class="ordbox">
		<view class="tabbox">
			<view :class="{'tabli':num==index}" v-for="(item,index) in tab" :key="index" @click="chantab(index)">{{item.name}}</view>
		</view>
		<view class="content">
			<view v-if="list==''" class="ordti">--暂无数据--</view>
			<view v-else class="">
				<view class="item" v-for="(item,index) in list" :key="index">
					<view class="top">
						<view class="orderid">订单编号：{{item.orderid}}</view>
						<text>{{item.status_text}}</text>
					</view>
					<view class="listbox" v-for="(subItem,subIndex) in item.product_list" :key="subIndex">
						<image class="listimage" :src="subItem.image" mode="aspectFill"></image>
						<view class="listte">
							<view class="litit">{{subItem.product_name}}</view>
							<view class="linav">数量：x{{subItem.num}}</view>
							<view class="lipic">￥{{subItem.total}}</view>
						</view>
					</view>
					<view class="bottom">
						<view class="btn" v-if="item.status == 10" @click="chenqr(item)">确定收货</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref,onMounted } from 'vue';
import {onLoad, onReachBottom} from '@dcloudio/uni-app'
import request from '../../utils/request';
let token=ref('')
onLoad(()=>{
	token.value = uni.getStorageSync('token')
	getData()
})
let pageSize = ref(15)
let page = ref(1)
let status = ref(-1)
let last_page = ref(1)
let	tab=ref([{
	name: '全部',
	status: -1
}, {
	name: '已支付',
	status: 1
}, {
	name: '已发货',
	status: 10
}, {
	name: '已完成',
	status: 20
}])
let num=ref(0)
let list=ref([])
const chantab=(index)=>{
	num.value=index
	status.value = tab.value[index].status
	page.value = 1
	list.value = []
	getData()
}

onReachBottom(() => {
	if(page.value == last_page.value){
		uni.$u.toast('已经是最后一页了')
	}else{
		page.value++
		getData()
	}
})

const getData = () => {
	if (page.value == 1) {
		list.value = []
	}
	request.post('Productorder/lists',{data:{
		page_size: pageSize.value,
		status: status.value,
		page: page.value
	},header:{
		"token":token.value
	}}).then(res=>{
		last_page.value = res.data.list.last_page
		// list.value=res.data.list.data
		if (res.code == 1) {
			res.data.list.data.forEach((item,index) => {
				list.value.push(item)
			})
		} else {
			uni.showToast({
				title:res.msg,
				icon:'none'
			})
		}
		console.log(list.value);
	}).catch(err=>{
		console.log(err);
	})
}
const chenqr=(item)=>{
	request.post('Productorder/confirmOrder',{data:{
		id:item.id
	},header:{
		"token":token.value
	}}).then(res=>{
		console.log(res);
		uni.$u.toast(res.msg)
		page.value = 1
		this.getData()
	}).catch(err=>{
		console.log(err);
	})
}
const gotoxiangq=(item)=>{
	const id=item.product_id
}
</script>

<style scoped lang="scss">
	.ordbox{
		width: 100%;
		min-height: 100vh;
		height: fit-content;
		background-color: #f8f8f8;
	}
	.tabbox{
		width: 100%;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		background-color: #fff;
	}
	.tabli{
		height: 90rpx;
		line-height: 90rpx;
		border-bottom: 1px solid #10c696;
	}
	
	.content {
		padding: 24rpx;
		box-sizing: border-box;
	}
	.ordti{
		font-size: 13px;
		text-align: center;
		margin-top: 20rpx;
		color: #5d5d5d;
	}
	
	.item {
		width: 100%;
		// height: 230rpx;
		height: fit-content;
		margin-top: 20rpx;
		box-shadow: 0 0 25px -25px rgba(0, 0, 0, .5);
		border-radius: 20rpx;
		background-color: #fff;
		padding: 24rpx;
		box-sizing: border-box;
		
		.top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 12rpx 0;
			box-sizing: border-box;
			margin-bottom: 10rpx;
			
			.orderid {
				font-size: 28rpx;
			}
			
			text {
				color: #10c696;
			}
		}
		
		.bottom {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			
			.btn {
				width: fit-content;
				height: 64rpx;
				border-radius: 32rpx;
				padding: 0 24rpx;
				line-height: 64rpx;
				text-align: center;
				background-color: #10c696;
				color: #fff;
				font-size: 24rpx;
				box-sizing: border-box;
			}
		}
	}
	.listimage{
		width: 170rpx;
		height: 170rpx;
		border-radius: 12rpx;
		margin-right: 24rpx;
	}
	.listbox{
		width: 100%;
		height: 170rpx;
		font-size: 14px;
		display: flex;
		align-items: center;
		margin-bottom: 24rpx;
	}
	.listte{
		width: calc(100% - 194rpx);
		height: 170rpx;
		display: flex;
		flex-direction: column;
	}
	.litit{
		font-size: 32rpx;
		margin-bottom: 10rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		word-break: break-all;
	}
	.linav{
		 display: -webkit-box;
		  -webkit-box-orient: vertical;
		  -webkit-line-clamp: 2; /* 设置最大显示行数 */
		  overflow: hidden;
		  font-size: 26rpx;
		  flex: 1;
	}
	.picbox{
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 60rpx;
		margin-top: 10rpx;
		
	}
	.picbutt{
		width: 150rpx;
		height: 50rpx;
		border-radius: 20rpx;
		line-height: 50rpx;
		text-align: center;
		background-color: #10c696;
		color: #fff;
		font-size: 12px;
	}
	.lipic{
		color: red;
		font-size: 14px;
	}
</style>
